package create.singletonPattern.Demo02;

/**
 * @ClassName Singleton
 * @Description 单例模式--懒汉式
 * @Author 李明忠
 * @Date 2025/5/8 16:38
 * @Version 1.0
 */
public class Singleton {
    //1.构造私有化
    private Singleton(){

    }
    //2.静态对象
    private static Singleton instance;
    //3.提供访问对象的唯一方式
    //懒汉式线程安全---双重检查方式
    public static Singleton getSingleton() {
        if (instance == null){
            synchronized (Singleton.class){
                if (instance == null){
                    instance = new Singleton();
                }
            }
        }
        return instance;
    }
}
